﻿using FairyGUI;

/// <summary>
/// 个人中心页面
/// </summary>
public class UIUserInfoWindow : UIPopupWindow {

    public UIUserInfoWindow()
    {
        // 加载界面
        base.Init(UIPackage.CreateObject("大厅", "个人中心").asCom);

        // 个人中心
        GComponent personCenter = uiComp.GetChild("个人中心").asCom;

        // 初始化关闭按钮
        GButton closeBtn = personCenter.GetChild("关闭按钮").asButton;
        closeBtn.onClick.Add(() => {
            DebugInfo.Log("关闭个人中心");

            AudioController.inst.PlayUIClickEffect();
            uiComp.RemoveFromParent();
            uiComp.Dispose();
            base.Close();
        });

        // 初始化用户信息显示
        UserInfo userInfo = DataKernel.inst.userInfo;
        GTextField usernameCtrl = personCenter.GetChild("用户名").asTextField;
        usernameCtrl.text = userInfo.name;
        GTextField useridCtrl = personCenter.GetChild("用户编号").asTextField;
        useridCtrl.text = "ID: " + userInfo.uid;
        GTextField ipCtrl = personCenter.GetChild("用户地址").asTextField;
        ipCtrl.text = "IP: " + userInfo.ip;
        GTextField cardCtrl = personCenter.GetChild("房卡数量").asTextField;
        cardCtrl.text = "" + userInfo.card;

        UIHeadpicImage headpicImg = new UIHeadpicImage(personCenter.GetChild("头像").asCom);
        headpicImg.SetHeadpic(userInfo.headpic);
    }

    /// <summary>
    /// 弹出窗口
    /// </summary>
    public static void Popup()
    {
        DebugInfo.Log("打开个人中心");
        UIRootController.inst.PopupWindow(new UIUserInfoWindow());
    }
}
